﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace B2B.Models
{
    public class SP_DangNhap
    {
        int maTV;

        public int MaTV
        {
            get { return maTV; }
            set { maTV = value; }
        }
        string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        string password;

        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        string hoTen;

        public string HoTen
        {
            get { return hoTen; }
            set { hoTen = value; }
        }

        public static SP_DangNhap dangNhap(string email, string password)
        {
            SP_DangNhap tv_dn = null;
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_DANGNHAP",conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EMAIL", email);
            cmd.Parameters.AddWithValue("@PASSWORD", password);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                tv_dn = new SP_DangNhap();
                tv_dn.MaTV = reader.GetInt32(0);
                tv_dn.Email = reader.GetString(1);
                tv_dn.Password = reader.GetString(2);
                tv_dn.HoTen = reader.GetString(3);
            }
            return tv_dn;
        }
    }
}